<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复选框和小复选框</title>
    <style>
        div{
            height: 300px;
            border: 1px solid black;
        }
        table{
            border-collapse: collapse;
        }
        thead{
            background-color: rgb(49, 173, 231);
        }
        td{
            border: 1px solid gray;
            padding: 15px;
        }
        /* .checkAll{
            float: left;
        } */
        .checkAll:checked {

            /* width: 20px;
            height: 20px; */

        }
    </style>
</head>
<body>
    <div>
       <table>
        <thead>
            <tr class="head">
                <th><input type="checkbox" name="" class="checkAll">全选</th>
                <th>商品</th>
            </tr>
           </thead>
            <tr>
                <td><input type="checkbox" name="check" class="ck"></td>
                <td>英特尔i5处理器</td>
            </tr>
            <tr>
                <td><input type="checkbox" name="check" class="ck"></td>
                <td>北极狐电脑主板</td>
            </tr>
            <tr>
                <td><input type="checkbox" name="check" class="ck"></td>
                <td>罗技圣剑键盘</td>
            </tr>
       </table>
    </div>
    <script>
        const checkAll = document.querySelector('.checkAll')
        const cks = document.querySelectorAll('.ck')
        checkAll.addEventListener('click',function(){
            for (let i=0; i < cks.length ; i++){
                cks[i].checked = this.checked
            }
        })

        for (let i=0 ; i < cks.length ; i++){
            cks[i].addEventListener('click',function(){
                checkAll.checked = document.querySelectorAll('.ck:checked').length === cks.length
            })
        }
    </script>
</body>
</html>
